package com.yzg.lock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author misterWei
 * @create 2020年06月20号:19点17分
 * @mailbox forcontinue@163.com
 */
@Slf4j(topic = "c.LockReentrant")
public class LockReentrant {

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock(false);
        try {
            if (lock.tryLock(5000L, TimeUnit.SECONDS)) {

                lock.lock();
                try {

                    System.out.println(1);
                }finally {
                    lock.unlock();
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
          //  lock.unlock();
        }
        new Thread(()->{
            lock.lock();
            log.info("{}","out");
        }).start();


    }



}
